package com.accelstack.cmp.service;

import com.accelstack.cmp.entity.PhysicalGpu;
import com.accelstack.cmp.repository.PhysicalGpuRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * 物理GPU Service
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class PhysicalGpuService {
    
    private final PhysicalGpuRepository physicalGpuRepository;
    
    @Transactional
    public PhysicalGpu create(PhysicalGpu physicalGpu) {
        return physicalGpuRepository.save(physicalGpu);
    }
    
    @Transactional
    public PhysicalGpu update(PhysicalGpu physicalGpu) {
        return physicalGpuRepository.save(physicalGpu);
    }
    
    @Transactional
    public void deleteById(Long id) {
        physicalGpuRepository.deleteById(id);
    }
    
    public Optional<PhysicalGpu> findById(Long id) {
        return physicalGpuRepository.findById(id);
    }
    
    public List<PhysicalGpu> findAll() {
        return physicalGpuRepository.findAll();
    }
    
    public Page<PhysicalGpu> findAll(Pageable pageable) {
        return physicalGpuRepository.findAll(pageable);
    }
    
    public List<PhysicalGpu> findByServerId(Long serverId) {
        return physicalGpuRepository.findByServerId(serverId);
    }
}

